button_query_onclick = function () 
{   	
	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCN10","query");
}
button_update_onclick = function (){ 
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能修改草拟状态的记录！"); return;
		}
	}
	efgrid.submitForm( "ef_grid_r", "ZM","ZMCN10","update",true);
}
button_insert_onclick = function (){
	if (isSelected("ef_grid_r") == 0)return; 
	efgrid.submitForm( "ef_grid_r", "ZM","ZMCN10","insert",true);
/*	var info = getSCZXEiInfos("ZMCN10","ef_grid_r");
	if (null != info) { 
		EiCommunicator.send("ZMCN10", "validate", info, validate_callback);
	}
*/} 

button_delete_onclick = function (){
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能删除草拟状态的记录！"); return;
		}
	}
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r){
			efgrid.submitForm( "ef_grid_r", "ZM","ZMCN10","delete",true);
/*			var info = getSCZXEiInfos("ZMCN10","ef_grid_r");
			if (null != info) { 
				EiCommunicator.send("ZMCN10", "validate1", info, validate1_callback);
			}*/
		}
	}); 
}
var validate1_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
				if(eiInfo.get("efCurButtonEname")=="UPDATE"){
					//可以修改，然后再进行重复性校验
					EiCommunicator.send("ZMCN10", "validate", eiInfo, validate_callback);
				}else{
					$('#ef_region_detail').hide();
					//执行删除操作
					efgrid.submitForm( "ef_grid_r", "ZM","ZMCN10","delete",true);
				}
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}
var validate_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
/*				 efwindow.hide();
				 var grid = efgrid.getGridObject("ef_grid_r");
				 grid.refresh(eiInfo);*/
				var oper="insert";
				if(eiInfo.get("efCurButtonEname")=="UPDATE"){
					oper="update";
				}
				efgrid.submitForm("ef_grid_r", "ZM", "ZMCN10",oper, true);
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}
button_report_onclick = function (){
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("该记录或有记录已经生效！"); return;
		}
	}
	EFConfirm('你确认要生效吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_r", "ZM","ZMCN10","report",true);
	}); 
}
efgrid_afterAddNewRow = function(grid_id){ 
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();  
	if(grid_id=="ef_grid_r")
	{
		for(var i = 0 ; i < rows.length;i++){
			grid.getBlockData().setCell(rows[i], "fdStatus", "草拟");		
            grid.getBlockData().setCell(rows[i],"fdKeyId","")
		}
	}
}